package cn.com.blueInfo.bpm.template.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.template.request.ProcessNodeDTO;
import cn.com.blueInfo.bpm.template.response.ProcessNodeVO;
import cn.com.blueInfo.bpm.template.service.ProcessNodeService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 模板节点定义表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:41:15
 */
@Tag(name = "模板节点定义 接口")
@RestController
@RequestMapping("/template/processNode")
public class ProcessNodeController extends BaseController {

    @Autowired
    private ProcessNodeService processNodeService;

    /**
     * 新建模板节点定义
     * @param processNodeDTO 模板节点定义参数
     * @return ResultInfo
     */
    @Operation(summary = "新增模板节点定义")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createProcessNode(
            @Validated({Create.class, Default.class}) @RequestBody ProcessNodeDTO processNodeDTO) {
        return processNodeService.addProcessNode(processNodeDTO);
    }

    /**
     * 批量新建模板节点定义
     * @param processNodeDTOList 模板节点定义参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建模板节点定义")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateProcessNode(
            @Validated({Create.class, Default.class}) @RequestBody List<ProcessNodeDTO> processNodeDTOList) {
        return processNodeService.batchAddProcessNode(processNodeDTOList);
    }

    /**
     * 根据ID删除模板节点定义
     * @param processNodeId 模板节点定义ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除模板节点定义")
    @DeleteMapping("/removeInfo/{processNodeId}")
    public ResultInfo<Integer> deleteProcessNodeById(
            @Parameter(name = "ID") @PathVariable Long processNodeId) {
        return processNodeService.removeProcessNode(processNodeId);
    }

    /**
     * 批量根据ID删除模板节点定义
     * @param processNodeIdList 模板节点定义ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除模板节点定义")
    @DeleteMapping("/removeInfoList/{processNodeIdList}")
    public ResultInfo<Integer> batchDeleteProcessNodeById(
            @Parameter(name = "ID") @PathVariable List<Long> processNodeIdList) {
        return processNodeService.batchRemoveProcessNode(processNodeIdList);
    }

    /**
     * 根据ID全量更新模板节点定义
     * @param processNodeId 模板节点定义ID
     * @param processNodeDTO 模板节点定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新模板节点定义")
    @PutMapping("/modifyInfo/{processNodeId}")
    public ResultInfo<Integer> updateProcessNodeFull(
            @Parameter(name = "ID") @PathVariable Long processNodeId,
            @Validated({Update.class, Default.class}) @RequestBody ProcessNodeDTO processNodeDTO) {
        validateUpdateId(processNodeId, processNodeDTO.getId());
        return processNodeService.modifyProcessNode(processNodeDTO);
    }

    /**
     * 根据ID部分更新模板节点定义
     * @param processNodeId 模板节点定义ID
     * @param processNodeUpdatePartialDTO 模板节点定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新模板节点定义")
    @PatchMapping("/modifyPartialInfo/{processNodeId}")
    public ResultInfo<Integer> updateProcessNodePartial(
            @Parameter(name = "ID") @PathVariable Long processNodeId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            ProcessNodeDTO.UpdatePartialDTO processNodeUpdatePartialDTO) {
        validateUpdateId(processNodeId, processNodeUpdatePartialDTO.getId());
        return processNodeService.modifyProcessNodePartial(processNodeUpdatePartialDTO);
    }

    /**
     * 根据ID查询模板节点定义
     * @param processNodeId 模板节点定义ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询模板节点定义")
    @GetMapping("/getInfo/{processNodeId}")
    public ResultInfo<ProcessNodeVO> getProcessNodeById(
            @Parameter(name = "ID") @PathVariable Long processNodeId) {
        return processNodeService.queryProcessNodeById(processNodeId);
    }

    /**
     * 分页查询模板节点定义
     * @param processNodeQueryDTO 模板节点定义参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询模板节点定义")
    @GetMapping("/getInfos")
    public ResultInfo<Page<ProcessNodeVO>> getProcessNodePage(
            @Validated ProcessNodeDTO.QueryDTO processNodeQueryDTO) {
        return processNodeService.queryProcessNodePage(processNodeQueryDTO);
    }

    /**
     * 根据条件查询模板节点定义
     * @param processNodeQueryDTO 模板节点定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询模板节点定义")
    @GetMapping("/getInfoList")
    public ResultInfo<List<ProcessNodeVO>> getProcessNodeList(
            @Validated ProcessNodeDTO.QueryDTO processNodeQueryDTO) {
        return processNodeService.queryProcessNodeList(processNodeQueryDTO);
    }

}
